package com.goudan.rabbitmq.util;

import com.goudan.rabbitmq.manager.EventDispatcher;
import com.goudan.rabbitmq.message.MsgData;
import com.goudan.rabbitmq.support.SpringContextHolder;

/**
 * MQ发送消息工具类
 */
public class EventDispatcherUtil {

    private static EventDispatcher eventDispatcher;

    public static void eventDispatch(MsgData<?> msgData, Integer delay) {
        if (eventDispatcher == null) {
            eventDispatcher = SpringContextHolder.getBean("eventDispatcher");
        }
        eventDispatcher.eventFanoutDispatch(msgData, delay);
    }

    public static void eventDispatch(MsgData<?> msgData) {
        if (eventDispatcher == null) {
            eventDispatcher = SpringContextHolder.getBean("eventDispatcher");
        }
        eventDispatcher.eventFanoutDispatch(msgData);
    }

    public static void eventDispatch(MsgData<?> msgData, String routingKey) {
        if (eventDispatcher == null) {
            eventDispatcher = (EventDispatcher) SpringContextHolder.getBean("eventDispatcher");
        }
        eventDispatcher.eventDispatchWithKey(msgData, routingKey);
    }
}
